package com.cqs.leetcode.tree.DFS;

import com.cqs.leetcode.TreeNode;

/**
 * lixw
 * 2021/11/5
 **/
public class SumLeftLeaves404 {

    private int sum = 0;

    public int sumOfLeftLeaves(TreeNode root) {
        dfs(root, false);
        return sum;
    }

    private void dfs(TreeNode node, boolean isLeft) {
        if (node == null) {
            return;
        }
        //is leave
        if (node.left == null && node.right == null) {
            if (isLeft) {
                sum += node.val;
            }
            return;
        }

        dfs(node.left, true);
        dfs(node.right, false);
    }


    public int tribonacci(int n) {
        int[] tmp = new int[3];
        tmp[1] = 1;
        tmp[2] = 1;
        if (n <= 2) return tmp[n];
        for (int i = 3; i <= n; i++) {
            int val = tmp[0] + tmp[1] + tmp[2];
            tmp[0] = tmp[1];
            tmp[1] = tmp[2];
            tmp[2] = val;
        }
        return  tmp[2];
    }

    public static void main(String[] args) {
        System.out.println(1 ^ 1);
        System.out.println(0 ^ 2);
    }
}
